<html>
<body>
<h1>Bestelgegevens</h1>
<?php
session_start();

include('../connect_db.php');
	   
		if(isset($_POST['emptycart']))
		{
			unset($_SESSION['winkelwagen']);
		}
		
		if(isset($_POST['savecart']))
		{
			if(isset($_SESSION['userlogin']))
			{
				$klantid = $_SESSION['klantid'];
				$savetodb = serialize($_SESSION['winkelwagen']);
				$winkelwagen_result = mysql_query("SELECT klantid, winkelmand FROM winkelwagen WHERE klantid = $klantid");
				$winkelwagen_num_rows = mysql_num_rows($winkelwagen_result);
				if($winkelwagen_num_rows == 0)
				{
					mysql_query("INSERT INTO winkelwagen(`klantid`, `winkelmand`) VALUES('$klantid', '$savetodb')");
				}
				else
				{
					mysql_query("UPDATE winkelwagen SET `winkelmand` = '$savetodb' WHERE `klantid` = '$klantid')");
				}
			}
			else
			{
				header('location: login.php');
			}
		}
		
		if(isset($_SESSION['winkelwagen']))
		{				
			$winkelwagen = $_SESSION['winkelwagen'];
			$totaal_kosten = 0;
			foreach($winkelwagen as $items)
			{
				$productid = $items['productid'];
				$product_result = mysql_query("SELECT Naam, Prijs FROM producten WHERE Productid = '".$productid."'");
				$product_row = mysql_fetch_array($product_result);
				
				$kosten = $items['prijs'] * $items['aantal'];
				$totaal_kosten = $totaal_kosten + $kosten;
				
				echo	"<div class='cart-small'>
						<div class='cart-small-name'><a href='product.php?pid=".$productid."'>$product_row[Naam]</a></div>
						<br />
						<div class='cart-small-price'>&euro; ".$items['prijs']."</div>
						<div class='cart-small-aantal'><a href='".$_SESSION['lastpage']."&add=-1'>
						<img src='images/button_minus.gif' border='0' /></a> &nbsp;".$items['aantal']."&nbsp; <a href='".$_SESSION['lastpage']."&add=1'>
						<img src='images/button_plus.gif' border='0' /></a>
						</div>
						<div class='cart-small-price'>&euro; $kosten</div>
						<div class='clear'></div></div>";						
			}
			echo	"<p style='font-size:14px; font-weight:bold; text-align:center;'>Totaal: &euro; ".$totaal_kosten."</p>
					<form action='".$_SESSION['lastpage']."' method='POST'>
					<center>
					<p>
					<input type='submit' name='emptycart' value='&nbsp;&nbsp;&nbsp;' style='height:37px; width:37px; background:url(images/shpcartclose_32.gif) no-repeat;'>			 					&nbsp;&nbsp;&nbsp;
					<input type='submit' name='savecart' value='&nbsp;&nbsp;&nbsp;' style='height:37px; width:37px; background:url(images/shpcartsave_32.gif) no-repeat;'>
					&nbsp;&nbsp;&nbsp;
					<input type='submit' name='checkout' value='&nbsp;&nbsp;&nbsp;' style='height:37px; width:37px; background:url(images/shpcartok_32.gif) no-repeat;'>
					</p>
					</center>
					</form>";
		}
		else
		{
			echo	"Uw winkelmandje is leeg";
		}
	

?>
</body>
</html>